<template>
  <div>
    <div class="systitle">学生宿舍管理系统</div>
    <div class="login_container">

        <div class="login_box">
            <div class="avatar_box">
                <img src="@/assets/logo.png" />
            </div>

            <el-form
                    ref="loginForm"
                    :model="loginForm"
                    label-width="0px"
                    class="login_form"
            >
                <el-form-item prop="userCode">
                    <el-input
                        prefix-icon="el-icon-user"
                        placeholder="用户名"
                        v-model="loginForm.username">
                    </el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input
                            prefix-icon="el-icon-lock"
                            placeholder="密码"
                            v-model="loginForm.password"
                            type="password"
                    ></el-input>
                </el-form-item>
                <el-form-item class="btns">
                    <el-button type="primary" @click="login">登录</el-button>
                    <el-button type="info" @click="resetLogin">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
  </div>
</template>
<script>
    export default {
        data() {
            return {
                loginForm: {
                    username: "",
                    password: ""
                }
            };
        },
        methods: {
          resetLogin(){

          },
            login() {
              this.axios.post('http://localhost:9000/users/login?username='+this.loginForm.username+"&password="+this.loginForm.password)
                  .then(res=>{
                  if(res.data=='登录失败'){
                    this.$message({
                      message: res.data,
                      type: 'error'
                    })
                  }else{
                    localStorage.setItem("jwttoken",res.data)
                    // document.cookie = "jwttoken="+res.data+";path=/;domain=localhost";
                    location.href='http://localhost:8080/home'
                    // this.$router.push('/home')
                  }
              })
            }
        }
    };
</script>
<style lang="less" scoped>
    .systitle{
      font-size: xx-large;
      margin-top: 50px;
    }
    .login_container {
        background-color: #2b4b6b;
        height: 100%;
    }
    .login_box {
        width: 450px;
        height: 300px;
        background-color: #fff;
        border-radius: 3px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        .avatar_box {
            height: 100px;
            width: 100px;
            border-radius: 50%;
            border: 1px solid #eee;
            padding: 10px;
            box-shadow: 0 0 10px #ddd;
            position: absolute;
            left: 50%;
            transform: translate(-50%, -30%);
            background-color: #fff;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
                background-color: #eee;
            }
        }
    }
    .btns {
        display: flex;
        justify-content: flex-end;
    }
    .login_form {
        position: absolute;
        bottom: 0;
        width: 100%;
        padding: 0 10px;
        box-sizing: border-box;
    }
</style>
